package com.appkubes.mall.restful.application.user.account.account.controller;

import com.appkubes.base.core.entity.vo.UserKeyVO;
import com.appkubes.cloud.config.params.paramValid.ParamValid;
import com.appkubes.common.Response;
import com.appkubes.mall.restful.application.common.base.BaseController;
import com.appkubes.mall.restful.application.user.account.account.entity.dto.AccountStatisDTO;
import com.appkubes.mall.restful.application.user.account.account.entity.vo.WithDrawVO;
import com.appkubes.mall.restful.application.user.account.account.service.UserAccountService;
import com.appkubes.mall.restful.application.user.account.history.service.UserAccountHistoryService;
import com.appkubes.mall.restful.application.user.account.withdraw.service.AccountWithdrawService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * @Author: Rongjie
 * @Date: 2020/1/13 21:30
 * @Description:
 */
@Slf4j
@Api(tags = "用户账户")
@RestController
@RequestMapping("/user/account")
public class UserAccountController extends BaseController {
    @Resource
    UserAccountHistoryService historyService;

    @Resource
    UserAccountService accountService;

    @Resource
    AccountWithdrawService accountWithdrawService;

    @ApiOperation("查询账户余额")
    @GetMapping("/getBrokerage")
    public Response getBrokerage(@ParamValid UserKeyVO userKeyVO) {
        return Response.success(accountService.getById(userKeyVO.getUserKey()));
    }

    @ApiOperation("用户提现")
    @PostMapping("/withdraw")
    public Response withdraw(@RequestBody @ParamValid WithDrawVO withDrawVO) {
        Boolean ret = accountWithdrawService.addWithdrawLog(withDrawVO);
        if (ret) {
            return Response.success();
        }
        return Response.error("提现失败");
    }

    @ApiOperation("查询当天记录")
    @GetMapping("/getTodayStatis")
    public Response<AccountStatisDTO> getTodayStatis(@ParamValid UserKeyVO userKeyVO) {
        AccountStatisDTO accountStatisDTO = historyService.getTodayStatis(userKeyVO);

        return Response.success(accountStatisDTO);
    }
}
